home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / GETPIXEL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.1 KB  |  47 lines

  1.                                             /* getpixel.c */
  2.                                  /* Entered by A. Wayner */
  3.  
  4. # include <graphics.h>
  5.  
  6. main()
  7. {
  8.     int graphdriver = DETECT;
  9.     int graphmode, x, y, color;
  10.  
  11.                                             /* Detect adapter type and    */
  12.                                             /* initialize graphics system */
  13.       initgraph( &graphdriver, &graphmode, "\\turboc");
  14.     outtextxy( 10, 10, "Changing colors using getpixel with putpixel ");
  15.  
  16.                                             /* Draw a red bordered rectangle */
  17.     setcolor( RED );
  18.     rectangle( 70, 50, 130, 80 );
  19.     outtextxy( 10,20,"Press any key to turn red into blue " );
  20.     getch();
  21.  
  22.                                             /* Go over a rectangular region and */
  23.                                             /* change red to blue */
  24.     for( x = 50; x < 150; x++ )
  25.     {
  26.         for( y = 40; y < 90; y++ )
  27.         {
  28.             if( getpixel(x,y)==0 )    /* It's background */
  29.             {
  30.                 putpixel(x,y,RED);    /* Turn pixel red */
  31.                 continue;                /* skip next check */
  32.             }
  33.  
  34.             if( getpixel(x,y)==RED)    /* It's a red pixel */
  35.             {
  36.                 putpixel(x,y,BLUE );    /* Turn pixel blue */
  37.             }
  38.         }
  39.     }
  40.  
  41.     outtextxy( 10, getmaxy() - 30,"Press any key to exit : ");
  42.  
  43.     getch();                                /* Wait until a key is pressed */
  44.     closegraph();                        /* Exit graphics library */
  45.  
  46. }
  47.